package us.wili.dev.client.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import us.wili.dev.client.model.req.SearchReq;
import us.wili.dev.client.model.rsp.ActivityRsp;
import us.wili.dev.client.model.rsp.GoodsRsp;
import us.wili.dev.client.model.rsp.ShowClothRsp;
import us.wili.dev.client.service.ClientActivityService;
import us.wili.dev.client.service.ClientGoodsService;
import us.wili.dev.client.service.ClientHotService;
import us.wili.dev.client.service.ClientRotaService;
import us.wili.dev.common.model.Pager;
import us.wili.dev.common.model.PagerResponseDto;
import us.wili.dev.common.model.ResponseDto;
import us.wili.dev.common.util.ResponseUtil;
import us.wili.dev.model.entity.Rota;

import javax.validation.Valid;
import java.util.List;

@Validated
@RestController
@RequestMapping("/api/index")
@Api(tags = "首页")
public class IndexController {
    @Autowired
    private ClientActivityService clientActivityService;

    @Autowired
    private ClientRotaService clientRotaService;

    @Autowired
    private ClientHotService clientHotService;

    @Autowired
    private ClientGoodsService clientGoodsService;



    @ApiOperation(value = "轮播图", nickname = "rota")
    @RequestMapping(value = "/rota", method = RequestMethod.GET)
    public ResponseDto <List<Rota>> rota(){
        List<Rota> list =clientRotaService.rotas();
        return ResponseUtil.getSuccessRsp(list);
    }

    @ApiOperation(value = "轮播图跳转", nickname = "rotajump")
    @RequestMapping(value = "/rotajump", method = RequestMethod.GET)
    public ResponseDto<GoodsRsp> rotajump(Long id) {
        GoodsRsp rsp =clientRotaService.rotajump(id);
        return ResponseUtil.getSuccessRsp(rsp);
    }

    @ApiOperation(value = "热门面料", nickname = "hot")
    @RequestMapping(value = "/hot", method = RequestMethod.GET)
    public ResponseDto <GoodsRsp> hot(){
        List<GoodsRsp> list =clientHotService.hot();
        return ResponseUtil.getSuccessRsp(list);
    }

    @ApiOperation(value = "搜索", nickname = "search")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public PagerResponseDto<GoodsRsp> search(@Valid SearchReq req) {
        Pager<GoodsRsp> search = clientGoodsService.search(req);
        return new PagerResponseDto<>(search);
    }

    @ApiOperation(value = "活动推荐", nickname = "Activity")
    @RequestMapping(value = "/Activity", method = RequestMethod.GET)
    public ResponseDto <ActivityRsp> Activity(){
        List<ActivityRsp> list =clientActivityService.Activity();
        return ResponseUtil.getSuccessRsp(list);
    }

    @ApiOperation(value = "活动详情", nickname = "ActivityDeta")
    @RequestMapping(value = "/ActivityDeta", method = RequestMethod.GET)
    public ResponseDto <ShowClothRsp> ActivityDeta(Long id){
        List<ShowClothRsp> list =clientGoodsService.ActivityDeta(id);
        return ResponseUtil.getSuccessRsp(list);
    }
}
